<?php

class Chart extends Controller
{
	function Chart()
	{
		parent::Controller();
		$this->load->helper('url');
		$this->load->plugin('jpgraph');
	}
	
	function index()
	{
		$data['title'] = "Using JpGraph from CodeIgniter 1.5";        
        $data['heading'] = "Example 0 in JpGraph 2.1.4";        
            
        // Setup Chart
        $ydata = array(11,12); // this should come from the model        
		$height[0] = count($ydata)*50;
        $graph = barchart($ydata, 'This is a Line Chart', $height[0]);  // add more parameters to plugin function as required
        $graph->xaxis->SetTickLabels(array('a','b','c','d'));
		
		$ydata2 = array(12,1,2,30);
		$height[1] = count($ydata2)*50;
		$graph2 = barchart($ydata2, 'Test2',$height[1]);
        
		$graph_file_name = 'test.png';    
		
		$graphs[0] = $graph;
		$graphs[1] = $graph2;
		$mgraph = combined_graph($graphs, $height);
		
		if (file_exists($graph_file_name))
		{
			unlink($graph_file_name);
		}
		$mgraph->Stroke('./'.$graph_file_name);
        $data['graph'] = $graph_file_name;
        
        $this->load->view('chart_view', $data);
		
	}

}